package org.example.eight;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import org.example.utils.RabbitMqUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 死信消费者
 */
public class DeadConsumer01 {
    //死信交换机
    public static final String DEAD_EXCHANGE = "dead_exchange";

    public static void main(String[] args) throws IOException, TimeoutException {
        //死信队列
        String deadQueue = "deadQueue";
        Channel channel = RabbitMqUtil.getChannel();
        DeliverCallback deliverCallback = (String message, Delivery delivery) -> {
            System.out.println("消息接收到了");
            System.out.println(new String(delivery.getBody()));
        };
        CancelCallback cancelCallback = message -> {
            System.out.println("消息取消了");
            System.out.println(message);
        };
        channel.basicConsume(deadQueue,deliverCallback,cancelCallback );
    }
}
